<template>
  <div class="city hideTabbar">
    <div class="top">
      <van-search
        v-model="searchValue"
        placeholder="城市/区域/位置"
        show-action
        shape="round"
        @cancel="cancelSearch"
      />
      <van-tabs v-model:active="activeTab" line-height="3">
        <template v-for="(value, key, index) in allCities" :key="index">
          <van-tab :title="value.title" :name="key"></van-tab>
        </template>
      </van-tabs>
    </div>
    <div class="content">
      <template v-for="(value, key, index) in allCities" :key="index">
        <city-group v-show="key === activeTab" :groupData="value"></city-group>
      </template>
      <!-- 解决切换tab，渲染速度慢，改用v-show -->
      <!-- <city-group :groupData="currentGroup"></city-group> -->
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from "vue";
import { useRouter } from "vue-router";
import useCityStore from "@/stores/modules/city";
import { storeToRefs } from "pinia";
import cityGroup from "./cpns/city-group.vue";
const router = useRouter();
const searchValue = ref("");
const cancelSearch = () => {
  router.back();
};
/* tab切换 */
const activeTab = ref(null);
/* 获取城市数据 */
const cityStore = useCityStore();
cityStore.getCityAllAction();
const { allCities } = storeToRefs(cityStore);
// const currentGroup = computed(() => allCities.value[activeTab.value]);
</script>

<style lang="less" scoped>
.city {
  .top {
    position: relative;
    z-index: 9;
  }
  .content {
    height: calc(100vh - 104px);
    overflow-y: auto;
  }
}
</style>
